<?php
	
	$rawQuestion = getLineFromFile("quiz1.txt", 3);
	echo var_dump($rawQuestion) . "<br/>";
	
	function getLineFromFile($filename, $lineNumber)
	{
		if($lineNumber < 1):
			echo "getLineFromFile() starts at line 1. Line $lineNumber was specified.<br />";
			return null;
		endif;
		echo var_dump($filename) . "<br/>";
		$fp = fopen($filename, "r");
		if(flock($fp, LOCK_SH)):
			$currLineNumber = 1;
			while($line = fgetss($fp, 512)):
				if($currLineNumber == $lineNumber):
					return $line;
				else:
					$currLineNumber++;
				endif;
			endwhile;
			flock($fp, LOCK_UN);
			fclose($fp);		
			return null;
		else: 
			echo "Trouble getting lock. Recursively calling getLineFromFile() again.";
			// sleep(1);
			getLineFromFile();
		endif;
	}
?>

